package com.sicau.socialpracticesystem.entity.vo.team;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sicau.socialpracticesystem.common.myenum.OriginAddressEnum;
import com.sicau.socialpracticesystem.common.myenum.TeamProgressEnum;
import com.sicau.socialpracticesystem.entity.vo.teammember.TeamMemberVO;
import com.sicau.socialpracticesystem.util.UserContext;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDate;
import java.util.List;

/**
 * <p>
 * 支队查询VO
 * </p>
 *
 * @author sxt && ttxxi
 * @since 2021-04-26
 */
@SuppressWarnings("unused")
@Data
@Accessors(chain = true)
@TableName("team_vo")
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "支队查询VO", description = "支队查询VO")
public class TeamVO implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "id")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty(value = "支队名称")
    private String teamName;

    @ApiModelProperty(value = "创建者(队长)id")
    private Integer creatorId;

    @ApiModelProperty(value = "创建者(队长)学号")
    private Integer creatorNumber;

    @ApiModelProperty(value = "创建者(队长)姓名")
    private String creatorName;

    @ApiModelProperty(value = "社会实践类型id")
    private Integer typeId;

    @ApiModelProperty(value = "社会实践类型")
    private String type;

    @ApiModelProperty(value = "开始时间")
    private LocalDate startTime;

    @ApiModelProperty(value = "结束时间")
    private LocalDate endTime;

    @ApiModelProperty(value = "指导老师")
    private String instructor;

    @ApiModelProperty(value = "团队容量")
    private Integer allMemberCount;

    @ApiModelProperty(value = "已招成员数量")
    private Integer hasMemberCount;

    @ApiModelProperty(value = "实践出发地")
    private Integer originAddress;

    @ApiModelProperty(value = "实践目标地详细地址")
    private String destinationAddress;

    @ApiModelProperty(value = "团队进度")
    private Integer progress;

    //下面这段代码我没看见哪里用了，所以先注释了
//    @TableField(exist = false)
//    @ApiModelProperty(value = "是否是队长")
//    private Boolean captain;

    @TableField(exist = false)
    @ApiModelProperty(value = "是否是队长")
    private List<TeamMemberVO> teamMemberVOList;

    public Boolean getCaptain() {
        try {
            return creatorId.equals(UserContext.get().getId());
        } catch (Exception e) {
            return false;
        }
    }

    public String getOriginAddress() {
        OriginAddressEnum addressEnum = OriginAddressEnum.getEnum(originAddress);
        return addressEnum != null ? addressEnum.getAddress() : null;
    }

    public Integer getProgress() {
        TeamProgressEnum teamProgressEnum = TeamProgressEnum.getEnum(progress);
        return teamProgressEnum != null
                ? endTime.isAfter(LocalDate.now()) ? teamProgressEnum.getId() : TeamProgressEnum.ENDED.getId()
                : null;
    }
}
